public class test10_17 {
    public static int minSubArrayLen(int[] nums, int s) {
        int sum = 0;
        int left = 0;
        int result = Integer.MAX_VALUE;
        for(int right = 0; right < nums.length; right++) {
            sum +=nums[right];
            while(sum >= s) {
                result = Math.min(result, right-left+1);
                sum -= nums[left++];
            }
        }
        return result == Integer.MAX_VALUE ? 0 : result;
    }
    public static void main(String[] args) {
        int[] nums = {2, 3, 1, 2, 4, 3};
        int s = 7;
        System.out.println(test10_17.minSubArrayLen(nums, s));
        
    }
}
